<template>
	<view class="order-container">
		<view class="order-card" v-for="(order, index) in orderList" :key="index" @click="generateTaskOrderDetailsa(order)">
			<!-- 左侧图片 -->
			<view class="order-left">
				<image :src="order.image.url" class="order-image" mode="aspectFill" />
			</view>

			<!-- 右侧信息 -->
			<view class="order-right">
				<view class="order-status">{{ order.status }}</view>
				<view class="order-time">{{ order.createdAt }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../api/Channel.js'
	import request from '../../api/index.js'
	import suffixAddress from '../../api/suffixAddress.js'
	export default {
		data() {
			return {
				orderList: [],
				pageNum: 1,
				pageSize: 20
			};
		},
		onLoad() {
			this.userTasks(this.pageNum, this.pageSize)
		},
		onReachBottom() {
			this.pageNum += 1;
			this.userTasks(this.pageNum, this.pageSize)
		},
		methods: {
			async userTasks(pageNum, pageSize) {
				let obj = {
					url: api.Channel + suffixAddress.add().userTasks,
					data: {
						pageNum,
						pageSize
					}
				}
				let res = await request(obj);
				this.orderList.push(...res.data.list)
				this.orderList.forEach(el=>{
					if(el.status == 'PENDING'){
						el.status = '待处理'
					}else if(el.status == 'RUNNING'){
						el.status = '执行中'
					}else if(el.status == 'SUCCEEDED'){
						el.status = '已完成' 
					}else if(el.status == 'FAILED'){
						el.status = '失败'
					}
				})
			
			},
			generateTaskOrderDetailsa(item){
				uni.navigateTo({
				  url: '/pages/generateTaskOrderDetails/generateTaskOrderDetails?id=' + item.taskId
				});
			}
		}
	};
</script>

<style lang="less">
	.order-container {
		padding: 20rpx;
		background: #f5f5f5;
		min-height: 100vh;
	}

	.order-card {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #fff;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
	}

	.order-left {
		width: 160rpx;
		height: 160rpx;
		margin-right: 20rpx;
	}

	.order-image {
		width: 100%;
		height: 100%;
		border-radius: 12rpx;
		object-fit: cover;
	}

	.order-right {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		text-align: right;
	}

	.order-time,
	.order-status {
		font-size: 26rpx;
		color: #333;
		margin-bottom: 30rpx;
	}
</style>